<!DOCTYPE html>
<html>
<head>
<title>template</title>
<meta name="keywords" charset=utf-8/>
<!--[if !IE]> -->
  <script src="http://cdn.bootcss.com/jquery/2.2.0/jquery.min.js"></script>
  <!-- <![endif]-->
  <!--[if IE]>
      <script src="http://cdn.bootcss.com/jquery/1.12.0/jquery.js"></script>
  <![endif]-->
<style>
*{
  margin:0;
  padding:0;
}

</style>
</head>
<body>
  <div>hello js</div>

<script>
var arr = [1,2,43];
var json = {a:6,b:4,c:[1,2,3]};
var str = 'sdfsdf';
var str2=deepClone(str);
console.log(str2);
var arr2=deepClone(arr);
console.log(arr2);
var json2=deepClone(json);
console.log(json2);
function deepClone(obj){
    var result;
    var oClass = isClass(obj);//确定result的类型       
    if(oClass==="Object"){
        result={};
    }else if(oClass==="Array"){
        result=[];
    }else{
        return obj;
    }
    for(key in obj){
        var copy=obj[key];
        if(isClass(copy)=="Object"){
            result[key]=arguments.callee(copy);//递归调用
        }else if(isClass(copy)=="Array"){
            result[key]=arguments.callee(copy);
        }else{
            result[key]=obj[key];
        }
    }
    return result;
}
//返回传递给他的任意对象的类
function isClass(o){
    if(o===null) return "Null";
    if(o===undefined) return "Undefined";
    return Object.prototype.toString.call(o).slice(8,-1);
}
</script>
</body>
</html>